package com.hngy.xpq.dianming;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, View.OnClickListener {
    TextView xpq,xh;
    Button button,button1;
    Spinner yy1,yy2,bj;

    int x = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        xpq = findViewById(R.id.text_xpq_xy);
        xh = findViewById(R.id.text_xpq_xh);
        yy2 = findViewById(R.id.dm_yy_02);
        yy1 = findViewById(R.id.dm_yy_01);
        bj = findViewById(R.id.dm_bj);
        button = findViewById(R.id.button_01);

        yy1.setOnItemSelectedListener(this);
        yy2.setOnItemSelectedListener(this);
        bj.setOnItemSelectedListener(this);

        button.setOnClickListener(this);
    }


    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        Random XingYun = new Random();
        int kelang = XingYun.nextInt(39) + 1;
        String a = String.valueOf(kelang);

        String[] indexXingYun1 = getResources().getStringArray(R.array.yy19_1);
        String[] indexXingYun2 = getResources().getStringArray(R.array.yy19_2);

        int aaa = bj.getSelectedItemPosition();

        if(aaa == 1){
            xh.setText("幸运学号:" + a);
            xpq.setText(indexXingYun1[kelang]);

        } else if(aaa == 2){
            xh.setText("幸运学号:" + a);
            xpq.setText(indexXingYun2[kelang]);
        }

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_01:
                Intent intent = new Intent(MainActivity.this,MainActivity_lord.class);
                startActivity(intent);
                break;
        }
    }
}